package com.yc.cloud.wechat.pay.controller;


import com.yc.cloud.basic.api.ResponseResult;
import com.yc.cloud.wechat.pay.vo.WxPrepayWithRequestPaymentVo;
import com.yc.cloud.wechat.pay.dto.request.WxCreateOrderParam;
import com.yc.cloud.wechat.pay.service.WxPayService;
import io.swagger.annotations.ApiOperation;
import lombok.val;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequestMapping("wx/pay")
@ApiIgnore
public class WxPayController {
    private final WxPayService wxPayService;

    public WxPayController(WxPayService wxPayService) {
        this.wxPayService = wxPayService;
    }

    @ApiOperation(value = "预支付订单", notes = "预支付订单")
    @PostMapping("/create")
    public ResponseResult<WxPrepayWithRequestPaymentVo> createOrder(@Validated @RequestBody WxCreateOrderParam param) {
        //创建初始化订单
        val result = wxPayService.createOrder(param);
        return result != null ? ResponseResult.success(result) : ResponseResult.failed();

    }
}
